local wuyuan = fk.CreateSkill {

  name = "joy__wuyuan",

  tags = {  },

}



wuyuan:addEffect("active", {
  name = "joy__wuyuan",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "#joy__wuyuan",
  can_use = function(self, player)
    return player:usedSkillTimes(wuyuan.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local card = Fk:getCardById(effect.cards[1])
    room:moveCardTo(card,Card.PlayerHand,target,fk.ReasonGive,wuyuan.name,nil,true,player)
    if not player.dead and player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = wuyuan.name
      })
    end
    if not player.dead then
      player:drawCards(1, wuyuan.name)
    end
    if not target.dead then
      if card.color == Card.Red and target:isWounded() then
        room:recover({
          who = target,
          num = 1,
          recoverBy = player,
          skillName = wuyuan.name
        })
      elseif card.color == Card.Black then
        room:addPlayerMark(target,"@joy__wuyuan",1)
      end
      local n = card.name ~= "slash" and 2 or 1
      target:drawCards(n, wuyuan.name)
    end
  end,
})

wuyuan:addEffect("targetmod", {
  name = "#joy__wuyuan_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@joy__wuyuan") > 0 then
      return player:getMark("@joy__wuyuan")
    end
    return 0
  end,
})

wuyuan:addEffect(fk.TurnEnd, {
  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@joy__wuyuan") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player,"@joy__wuyuan",0)
  end,
})

return wuyuan